/**
 * Created by nitin on 3/24/14.
 */
function GridCtrl($scope, $http) {
    $scope.productView = 9;
    $scope.gridCurrent = 0;
    $scope.gridSelect = "before";
    var productList=[];
    $http.get(BACK_END_URL+'index.php?format=json').success(function (data) {
        productList = data.posts;
    });

   /* $scope.productList = [
        {name: 'Nexus 7', img: 'background-image : url("https://www.google.com/nexus/images/comparison-devices.png")', price: '500', link: "#"},
        {name: 'Xperia™ Z2', img: 'background-image : url("http://api.sonymobile.com/files/xperia-z2-gallery-04-amazing-display-1240x840-1636d70e11527f212bebb67d794a78c1.jpg")', price: '500', link: "#"},
        {name: 'DK36', img: 'background-image : url("http://api.sonymobile.com/files/DK36-Magnetic-Charging-Dock-300x169-61bb2fa4df34b0babff48348736d2ee2.png")', price: '500', link: "#"},
        {name: 'SmartBand SWR10', img: 'background-image : url("http://api.sonymobile.com/files/swr10-smartband-black-1240x840-2da9bc94c4b36a0e7198dc05252efdde.jpg")', price: '500', link: "#"},
        {name: 'QX100', img: 'background-image : url("http://api.sonymobile.com/files/DSC-QX100-300x169-c3c458098e4631a4aa64abc495152f03.png")', price: '500', link: "#"},
        {name: 'Xperia™ Z Ultra', img: 'background-image : url("http://api.sonymobile.com/files/xperia-z-ultra-gallery-05-620x420-4791c8659a4629d4eea6859a919695c2.jpg")', price: '500', link: "#"},
        {name: 'BTV5', img: 'background-image : url("http://api.sonymobile.com/files/SRS-BTV5_Black_Main_JP-300x169.png")', price: '500', link: "#"},
        {name: 'Smart Wireless Headset pro', img: 'background-image : url("http://api.sonymobile.com/files/smart-wireless-headset-pro-product-image-300x169-3.png")', price: '500', link: "#"},
        {name: 'HTC Desire', img: 'background-image : url("http://www.htc.com/managed-assets/shared/desktop/smartphones/htc-desire-601/en_US/htc-desire-601-en_US-slide-01.png")', price: '500', link: "#"},

        {name: 'Power Cover CP12', img: 'background-image : url("http://api.sonymobile.com/files/CP12-300x169-6159afb9f221a12a58ff7eba35772cb2.png")', price: '500', link: "#"},
        {name: 'NFC NT3', img: 'background-image : url("http://api.sonymobile.com/files/SmartTags-NT3-300x169-43db1b986db4ae36feb935c9184680bb.png")', price: '500', link: "#"},
        {name: 'Nexus 5', img: 'background-image : url("https://www.google.com/nexus/images/nexus-5-new/learn_intro_1200.jpg")', price: '500', link: "#"},
        {name: 'Sony SmartWatch', img: 'background-image : url("http://api.sonymobile.com/files/smartwatch-product-image-300x169.png")', price: '500', link: "#"},
        {name: 'HTC One', img: 'background-image : url("http://www.htc.com/managed-assets/shared/desktop/smartphones/htc-one/hero/color-picker/silver.png")', price: '500', link: "#"},
        {name: 'Xperia™ M2', img: 'background-image : url("http://api.sonymobile.com/files/xperia-m2-black-1240x840-60271196b119d9cf8cac50e166e7c71f.jpg")', price: '500', link: "#"},
        {name: 'Xperia™ E1', img: 'background-image : url("http://api.sonymobile.com/files/xperia-e1-hero-black-1240x840-5f95d7ef7d74b55fc6da26dbabf9ca35.jpg")', price: '500', link: "#"},
        {name: 'Smart Wireless Headset pro', img: 'background-image : url("http://www-static.se-mc.com/blogs.dir/0/files/2012/11/smart-wireless-headset-pro-usp2-620x340.jpg")', price: '500', link: "#"},
        {name: 'Xperia™ L', img: 'background-image : url("http://api.sonymobile.com/files/xperia-l-white-PS-1240x840-3491848e4bfbac3ddf5587c4c953304a.jpg")', price: '500', link: "#"},

        {name: 'Xperia™ Z2', img: 'background-image : url("http://api.sonymobile.com/files/xperia-z2-gallery-05-waterproof-super-durable-1240x840-e7a7800851058db44b43a4da0a970888.jpg")', price: '500', link: "#"},
        {name: 'Xperia™ Z Ultra', img: 'background-image : url("http://api.sonymobile.com/files/xperia-z-ultra-gallery-03-620x420-57e34031b222a4c7d670b50230c43594.jpg")', price: '500', link: "#"},
        {name: 'HTC One 2', img: 'background-image : url("http://www.htc.com/managed-assets/shared/desktop/smartphones/htc-one-m8/pdp/image/explorer/htc-one-m8-en-slide-01-us.png")', price: '500', link: "#"},
        {name: 'Xperia™ E1', img: 'background-image : url("http://www-static.se-mc.com/blogs.dir/0/files/2013/12/xperia-e1-intro-black-19b0e3180941bb32154238a9b28575c2-940.jpg")', price: '500', link: "#"},
        {name: 'iPhone 5S', img: 'background-image : url("http://images.apple.com/iphone/compare/images/compare_iphone5s.jpg")', price: '500', link: "#"},
        {name: 'iPhone 4S', img: 'background-image : url("http://images.apple.com/iphone/compare/images/compare_iphone4s.jpg")', price: '500', link: "#"},
        {name: 'iPhone 5C', img: 'background-image : url("http://images.apple.com/iphone/compare/images/compare_iphone5c.jpg")', price: '500', link: "#"},
        {name: 'iPad Air', img: 'background-image : url("http://images.apple.com/ipad/compare/images/compare_hardware_images.jpg")', price: '500', link: "#"},
        {name: 'Xperia™ M2', img: 'background-image : url("http://api.sonymobile.com/files/xperia-m2-gallery-01-1240x840-c7ce2e35e380d3dcb5eaab82363e6f3c.jpg")', price: '500', link: "#"},

        {name: 'iPad Mini', img: 'background-image : url("http://images.apple.com/ipad/compare/images/compare_hardware_images.jpg")', price: '500', link: "#"},
        {name: 'iPod Touch', img: 'background-image : url("http://images.apple.com/ipod/compare-ipod-models/images/ipod_touch.jpg")', price: '500', link: "#"},
        {name: 'Xperia™ Z Ultra', img: 'background-image : url("http://api.sonymobile.com/files/xperia-z-ultra-gallery-01-620x420-b87e4fba39f98e4649a54bec182d3481.jpg")', price: '500', link: "#"}
    ];*/

    $scope.productPages = function (index) {
        var page = [];
        var tag = [];
        var pageNo = Math.ceil(productList.length / $scope.productView);
        for (var i = 0; i < pageNo; i++) {
            page.push(new Object(productList.slice(i * $scope.productView, (i + 1) * $scope.productView)));
            tag[i] = i;
        }
        if (index != undefined)
            return page[index];
        else return tag;
    }
    $scope.productSelected = function () {
        $scope.gridItemSelect = $scope.productPages($scope.gridCurrent)[this.$index];
        $scope.gridSelectDetailDisplay = true;
    }
    $scope.gridNumSelect = function () {
        if ($scope.gridCurrent == this.$index) return;
        if ($scope.gridSelect == "before")
            $scope.gridSelect = "after";
        else $scope.gridSelect = "before";
        $scope.gridCurrent = this.$index;
    };
}